/**
* @description: LeetCode 814
* @author hewei
* @date 2022/7/21 14:13
* @version 1.0
*/

public class PruneTree {

    public TreeNode pruneTree(TreeNode root) {
        if (root == null) return null;
        TreeNode l = pruneTree(root.left);
        TreeNode r = pruneTree(root.right);
        if (root.val == 0 && l == null && r == null) {
            return null;
        } else {
            root.left = l;
            root.right = r;
            return root;
        }
    }
}
